package com.masterclient.app.modules.shop.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselibrary.bean.shop.DealerShippingDetailBean;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.httpservice.RetrofitUtil2;

import org.json.JSONException;
import org.json.JSONObject;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import okhttp3.RequestBody;

/**
 * @auther hjian
 * @date 2020/9/12.
 */
public class DealerShippingDetailPresenter extends DealerShippingDetailContract.Presenter{

    @Override
    public void getShippingDetail(String delivery_id) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("delivery_id",delivery_id);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),
                jsonObject.toString());
        mRxManager.add(toSubscribe(RetrofitUtil2.getInstance().dealerShippingDetail(body), new Consumer<CommonBaseResponse<DealerShippingDetailBean>>() {
            @Override
            public void accept(@NonNull CommonBaseResponse<DealerShippingDetailBean> bean) throws Exception {
                if(bean.getCode() == 0){
                    mView.showData(bean.getData());
                }else {
                    mView.showFailure(bean.getMsg());
                }
            }
        }, new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.showFailure("网络异常，请重试");
            }
        }));
    }

}
